<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" autocomplete="off">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="nickname" placeholder="请输入用户昵称" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">支付状态</label>
                            <div class="layui-input-inline">
                                <select name="payStatus" id="payStatus">
                                    <option value="">选择支付状态</option>
                                    <option value="99">未支付</option>
                                    <option value="1">已支付</option>
                                    <option value="2">支付失败</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">观影状态</label>
                            <div class="layui-input-inline">
                                <select name="payState" id="payState">
                                    <option value="">选择观影状态</option>
                                    <option value="1">待观影</option>
                                    <option value="2">已观影</option>
                                    <option value="3">已失效</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">剧场</label>
                            <div class="layui-input-inline">
                                <select name="theatreCate" id="theatreCate">
                                    <option value="">选择剧场</option>

                                    {volist name ="theatreCate" id="vo"}
                                    <option value="{$vo.id}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">场馆</label>
                            <div class="layui-input-inline">
                                <select name="venue" id="venue">
                                    <option value="">选择场馆</option>

                                    {volist name ="venue" id="vo"}
                                    <option value="{$vo.id}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">演出</label>
                            <div class="layui-input-inline">
                                <select name="theatre" id="theatre">
                                    <option value="">选择演出</option>

                                    {volist name ="theatre" id="vo"}
                                    <option value="{$vo.id}">{$vo.title}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">演出时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="dtime" id="dtime" placeholder="请选择观影时间">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!--                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>-->
                <!--                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除</button>-->
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{# if (d.payStatus == 1){}}
            {{# if(d.state == 1){ }}
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="write">核销</a>
            {{# } }}
            {{# } }}
            <!--            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>-->
        </script>

    </div>
</div>
<script type="text/html" id="thumb">
    <img src="/{{d.thumb}}" alt="" style="width: 30px;height: 30px;" onclick="btn_img_src('/{{d.thumb}}')">
</script>
<script type="text/html" id="thumbImg">
    <img src="/{{d.thumb_img}}" alt="" style="width: 30px;height: 30px;" onclick="btn_img_src('/{{d.thumb_img}}')">
</script>
<script>
    layui.use(['form', 'table', 'laydate'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;

        laydate.render({
            elem: '#dtime'
            , type: 'datetime'
            , range: '~' //或 range: '~' 来自定义分割字符
            , value: "{$start_time} ~ {$end_time}"
        });
        let tableIns = table.render({
            elem: '#currentTableId',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',  //事件名，用于 toolbar 事件中使用
                icon: 'layui-icon-search'  //图标类名
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {
                    field: 'title', title: '演出名称', width: 180, templet: function (d) {
                        return d.GetTheatreIdData.title;
                    }
                },
                {
                    field: 'title', title: '场馆名称', width: 180, templet: function (d) {
                        return d.GetTheatreIdData.get_venue.title;
                    }
                },
                {
                    field: 'title', title: '剧场名称', width: 180, templet: function (d) {
                        return d.GetTheatreIdData.get_theatre_cate_id.title;
                    }
                },
                {field: 'number', width: 80, title: '张数', sort: true},
                {field: 'money', width: 80, title: '金额', sort: true},
                {
                    field: 'title', title: '头像', width: 100, templet: function (d) {
                        return '<img src="' + d.get_openid_user.avatarUrl + '" style="width: 30px;height: 30px;"/>';
                    }
                },
                {
                    field: 'title', title: '昵称', width: 100, templet: function (d) {
                        return d.get_openid_user.nickName;
                    }
                },
                {
                    field: 'mobile', title: '电话号码', width: 120
                },
                {
                    field: 'title', title: '演出时间', width: 180, templet: function (d) {
                        return d.GetTheatreIdData.start_time;
                    }
                },
                {
                    field: 'title', title: '核销码', width: 120, templet: function (d) {
                        return d.get_detail_data_code;
                    }
                },
                {
                    field: 'write_time', title: '核销时间', width: 180
                },
                {field: 'money', title: '金额', width: 80},
                {
                    field: 'id', title: '支付状态', width: 120, sort: true, templet: function (d) {
                        if (d.payStatus == 0) {
                            return '未支付';
                        } else if (d.payStatus == 1) {
                            return "支付成功";
                        }
                    }
                },
                {field: 'create_time', title: '下单时间', width: 180},
                {
                    field: 'id', title: '观影状态',width:120, sort: true, templet: function (d) {
                        if (d.state == 1) {
                            return '待观影';
                        } else if (d.state == 2) {
                            return "已演出";
                        } else if (d.state == 3) {
                            return "已失效";
                        } else if (d.state == 0) {
                            return "未支付"
                        }
                    }
                },
                {title:'操作',width:80,templet:'#currentTableBar'}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line',
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                , statusCode: 1 //规定成功的状态码，默认：0
                , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                , countName: 'count' //规定数据总数的字段名称，默认：count
                , dataName: 'data' //规定数据列表的字段名称，默认：data
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            tableIns.reload({
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            })
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                hadmin.add("添加", "{:url('add')}")
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            } else if (obj.event === 'LAYTABLE_TIPS') {
                $(".table-search-fieldset").slideToggle()
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                hadmin.add("编辑", "{:url('edit')}?eid=" + data.id)
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('您确定删除吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    hadmin.http("{:url('delete')}?eid=" + data.id).then(res => {
                        if (res.code === 1) {
                            layer.msg(res.msg, {icon: 6, shade: 0.5}, function () {
                                tableIns.reload()
                            })
                        }
                    })
                });
            } else if (obj.event === 'write') {
                layer.confirm('您确定核销吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    hadmin.http("{:url('write')}", data).then(res => {
                        if (res.code === 1) {
                            layer.msg(res.msg, {icon: 6, shade: 0.5}, function () {
                                tableIns.reload()
                            })
                        }
                    })
                });

            }

        });

    });
</script>
